package org.pp.controller;

import io.swagger.v3.oas.annotations.Operation;
import org.pp.admin.dto.*;
import org.pp.annotations.Permission;
import org.pp.core.PageBean;
import org.pp.core.Result;
import org.pp.entity.PpGoods;
import org.pp.service.IPpGoodsService;
import org.pp.vo.AdminMiniappGoodsDetailVo;
import org.pp.vo.AdminGoodsVo;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品 前端控制器
 * </p>
 *
 * @author haima
 */
@RestController
@RequestMapping("/goods")
public class PpGoodsController
    extends BaseCrudController<PpGoods, PpGoodsAdd, PpGoodsEdite, AdminGoodsVo>
    implements BaseAdd<PpGoodsAdd>,
        BaseEdite<PpGoodsEdite>,
        BaseDelete
{

    @Autowired
    IPpGoodsService goodsService;

    @Override
    @Permission("post:/goods/add")
    public Result<Object> add(PpGoodsAdd dto) {
        return super.add(dto);
    }

    @Override
    @Permission("post:/goods/edite")
    public Result<Void> edite(PpGoodsEdite dto) {
        return super.edite(dto);
    }

    @Override
    @Permission("post:/goods/delete")
    public Result<Void> delete(String ids) {
        return super.delete(ids);
    }


    @GetMapping("/list")
    @Permission("get:/goods/list")
    @Operation(summary = "分页查询")
    public Result<PageBean<AdminGoodsVo>> page(@ParameterObject PpGoodsPage page) {

        return Result.ok(goodsService.getPageList(page));
        //return super.page(page);
    }


    @PostMapping("/postage/update")
    @Operation(summary = "更新邮寄规则")
    public Result<Void> postageUpdate(@Validated @RequestBody PpGoodsPostageEdite dto){
        goodsService.postageUpdate(dto);
        return Result.ok();
    }

    @PostMapping("/detailIntro/update")
    @Operation(summary = "更新详细介绍信息")
    public Result<Void> detailIntroUpdate(@Validated @RequestBody PpGoodsDetailIntroEdite dto){
        goodsService.detailIntroUpdate(dto);
        return Result.ok();
    }

    @PostMapping("/attr/update")
    @Operation(summary = "更新属性信息")
    public Result<Void> attrUpdate(@Validated @RequestBody PpGoodsAttrEdite dto){
        goodsService.attrUpdate(dto);
        return Result.ok();
    }

    @PostMapping("/sku/update")
    @Operation(summary = "更新sku信息")
    public Result<Void> skuUpdate(@Validated @RequestBody PpGoodsSkuEdite dto){
        goodsService.skuUpdate(dto);
        return Result.ok();
    }


    @GetMapping("/detail")
    @Permission("get:/goods/detail")
    @Operation(summary = "获取商品详情")
    public Result<AdminMiniappGoodsDetailVo> getDetail(@RequestParam(name = "goodsId",required = true) Long goodsId){
        return Result.ok(goodsService.getDetail(goodsId));
    }

    @PostMapping("/categorize/update")
    @Operation(summary = "更新类别信息")
    public Result<Void> categorizeUpdate(@Validated @RequestBody PpGoodsCategorizeEdite dto){
        goodsService.categorizeUpdate(dto);
        return Result.ok();
    }

    @PostMapping("/status/switch")
    @Operation(summary = "上下架商品")
    public Result<Void> statusSwitch(@Validated @RequestBody PpGoodsStatusSwitch dto){
        goodsService.statusSwitch(dto);
        return Result.ok();
    }



}
